import request from '@/utils/request'
import { User, PaginationParams, PaginationResult } from '@/types'

/**
 * 获取用户列表
 */
export function getUserList(params: PaginationParams) {
  return request<PaginationResult<User>>({
    url: '/users',
    method: 'get',
    params
  })
}

/**
 * 创建用户
 */
export function createUser(data: Partial<User> & { password: string }) {
  return request<User>({
    url: '/users',
    method: 'post',
    data
  })
}

/**
 * 更新用户
 */
export function updateUser(id: number, data: Partial<User>) {
  return request<User>({
    url: `/users/${id}`,
    method: 'put',
    data
  })
}

/**
 * 删除用户
 */
export function deleteUser(id: number) {
  return request({
    url: `/users/${id}`,
    method: 'delete'
  })
}

/**
 * 重置密码
 */
export function resetPassword(id: number, newPassword: string) {
  return request({
    url: `/users/${id}/reset-password`,
    method: 'post',
    data: { password: newPassword }
  })
}

